/*
 * twi_interface.h
 *
 *  Created on: Oct 8, 2011
 *  Author: Mario H. Voorsluys
 *	email: forcaeluz@gmail.com
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, visit:
 * http://www.gnu.org/copyleft/gpl.html
 */

#ifndef TWI_INTERFACE_H_
#define TWI_INTERFACE_H_

#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/twi.h>

volatile unsigned char buffer[8];
volatile unsigned char last_status; //Every thing is fine.
void twi_init();
void twi_master_tx_slave(unsigned char addr, int read);
void twi_master_start();
void twi_master_tx_data(unsigned char data);
void twi_send_start(unsigned char addr);
void twi_send(unsigned char data);
void twi_finish();
unsigned char twi_request(unsigned char addr, int pos);
unsigned char twi_read_data(int ack);
unsigned char twi_buffered_value(int pos);

//Specific sonar:
int sonar_distance();
#endif /* TWI_INTERFACE_H_ */
